
const request = (options) => {
	return new Promise((resolve, reject) => {
		var BaseUrl = 'https://www.ikankan.top/api/v1';
		
		var url = "";
		if (BaseUrl && BaseUrl.length > 0) {
			url = `${BaseUrl}/${options.url}`
		} else {
			url = options.url;
		}
		var token = uni.getStorageSync('token');
		var header = {
			'Content-Type': options.contentType ?? 'application/json; charset=UTF-8'
		};
		if (options.header != 'none') {
			header.Authorization = `Bearer ${token}`;
		}
		uni.request({
			url: url, //仅为示例，并非真实接口地址。
			method: options.method,
			data: options.data,
			header: header,
			success: (res) => {

				if (res.statusCode == 200) {

					resolve(res.data);

				} else if (res.statusCode === 401) {
					//统一认证过期
					// localStorage.removeItem('userInfo');
					// localStorage.removeItem('token');
					localStorage.clear();
					reject("token过期")
				} else {

					reject(request.data.msg)
				}
			},
			fail(error) {
				reject(error.errMsg)

			}
		});
	})
}


module.exports = {
	request
}